package homework;

import org.junit.Test;

import java.util.Arrays;

public class Studenttest {
    public static void main(String[] args) {
        // 实例化学生数组
        Student[] students = {
                new Student(3, "张三", "计算机科学"),
                new Student(1, "李四", "软件工程"),
                new Student(2, "王五", "数学"),
                new Student(5, "赵六", "物理"),
                new Student(4, "钱七", "化学")
        };

        System.out.println("排序前的学生数组：");
        for (Student s : students) {
            System.out.println(s);
        }


        Arrays.sort(students);
        System.out.println("\n按学号升序排序后的学生数组：");
        for (Student s : students) {
            System.out.println(s);
        }


        Arrays.sort(students, (s1, s2) -> {
       
            if (s1.getName().length() != s2.getName().length()) {
                return Integer.compare(s1.getName().length(), s2.getName().length());
            } else {
                return s1.getName().compareTo(s2.getName());
            }
        });

        System.out.println("\n按姓名长度排序后的学生数组：");
        for (Student s : students) {
            System.out.println(s);
        }
    }



}
